package com.bugpool.leilema.tc.controller;

import cn.hutool.core.lang.tree.Tree;
import com.bugpool.leilema.tc.bean.entity.TreeEntity;
import com.bugpool.leilema.tc.service.TreeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Author wh
 * @Description
 * @Date 2023/2/28 9:10
 * @Version 1.0
 **/

@RestController
@RequestMapping("/tree")
@Api(tags = "树管理系统")
public class TreeController {

    @Resource
    private TreeService treeService;


    @PostMapping("/add")
    @ApiOperation("新增树结构")
    public boolean addTree(@RequestBody TreeEntity tree){
        return treeService.addTree(tree);
    }

    @PutMapping("/update")
    @ApiOperation("修改树结构属性")
    public boolean updateTree(@RequestBody TreeEntity tree){
        return treeService.updateTree(tree);
    }

    @GetMapping("/{id}")
    @ApiOperation("获取树详情")
    public TreeEntity getTreeEntity(@PathVariable Long id){
        return treeService.getTreeEntity(id);
    }

    @DeleteMapping("/{ids}")
    @ApiOperation("删除树")
    public boolean delByIds(@PathVariable List<Long> ids){
        return treeService.delByIds(ids);
    }

    @PutMapping("/userTree/{roleId}")
    @ApiOperation("数据图层绑定角色")
    public boolean userTree(@RequestBody List<Long> treeIds,@PathVariable Long  roleId){
        return treeService.buildRoleTree(treeIds,roleId);
    }





}
